package cn.edu.cdut.controller;

import cn.edu.cdut.dto.MyRes;
import cn.edu.cdut.dto.Notice;
import cn.edu.cdut.model.NoticeInfo;
import cn.edu.cdut.service.NoticeInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

/**
 * Author  kobe
 * Created on 2017-06-22-22:04
 */
@RestController
public class NoticeInfoController {
        @Autowired
        private NoticeInfoService noticeInfoService;

        @GetMapping("/getAllNotice")
        public MyRes getAllNotice() {
                return noticeInfoService.getAllNotice();
        }

        @GetMapping("/addNotice")
        public MyRes addNotice(Notice notice) {
                return noticeInfoService.addNotice(notice);
        }

        @PostMapping("/editNotice")
        public MyRes updateNotice(@RequestBody NoticeInfo noticeInfo, BindingResult bindingResult) {
                if (bindingResult.hasErrors()) {
                        return new MyRes(201, "提交失败！", null);
                }
                return noticeInfoService.updateNotice(noticeInfo);
        }

        @GetMapping("/removeNotice")
        public MyRes removeNotice(@RequestParam long id) {
                return noticeInfoService.removeNotice(id);
        }
}
